﻿<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <link href="css/bootstrap.css" rel="stylesheet" />
    <script src="js/jquery_2_1_min.js"></script>
    <script src="js/bootstrap.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>
    <script src="js/FastHttpApi.js"></script>
    <script src="js/api.js"></script>
    <title>
    </title>
</head>
<body>
    <div class="container bs-docs-container">
        <div class="row">
            <br />
            <div class="col-md-9" role="main">
                <nav class="navbar navbar-default">
                    <div class="container-fluid">
                        <!-- Brand and toggle get grouped for better mobile display -->
                        <div class="navbar-header">
                            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                                <span class="sr-only"></span>
                                <span class="icon-bar"></span>
                                <span class="icon-bar"></span>
                                <span class="icon-bar"></span>
                            </button>
                            <a class="navbar-brand" href="#">FastHttpApi http and websocket api</a>
                        </div>

                        <!-- Collect the nav links, forms, and other content for toggling -->

                    </div><!-- /.container-fluid -->
                </nav>
                <ul class="nav nav-tabs">
                    <li role="presentation"><a href="/">Orders</a></li>
                    <li role="presentation" class="active"><a href="/Employees.html">Employees</a></li>
                </ul>
                <div id="connectStatus" style="display:flex;padding-bottom:10px;"> </div>
                <div class="panel panel-default">
                    <div class="panel-body">
                        <form id="empInfo">
                            <div class="form-group">
                                <label for="exampleInputEmail1">First Name</label>
                                <input type="text" readonly class="form-control" id="FirstName" v-model:value="Data.FirstName" placeholder="First Name">
                            </div>
                            <div class="form-group">
                                <label for="exampleInputEmail1">Last Name</label>
                                <input type="text" readonly class="form-control" id="LastName" v-model:value="Data.LastName" placeholder="Last Name">
                            </div>
                            <div class="form-group">
                                <label for="exampleInputEmail1">Title</label>
                                <input type="text" class="form-control" id="Title" name="Title" v-model:value="Data.Title" placeholder="Title">
                            </div>
                            <div class="form-group">
                                <label for="exampleInputEmail1">Address</label>
                                <input type="text" class="form-control" id="Address" name="Address" v-model:value="Data.Address" placeholder="Address">
                            </div>
                            <div class="form-group">
                                <label for="exampleInputEmail1">City</label>
                                <input type="text" class="form-control" id="City" name="City" v-model:value="Data.City" placeholder="City">
                            </div>
                            <div class="form-group">
                                <label for="exampleInputEmail1">HomePhone</label>
                                <input type="text" class="form-control" id="HomePhone" name="HomePhone" v-model:value="Data.HomePhone" placeholder="HomePhone">
                            </div>
                            <button type="button" onclick="Modify()" class="btn btn-default">Submit</button>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
<script>

    var employeeID;
    var empInfoBlock;
    $(document).ready(function () {
        employeeID = getUrlVars()["id"];
        GetEmployee();

    });
    async function Modify() {

        var result = await HomeEditEmployee(employeeID, empInfoBlock.Data, true);
        if (result.Code == 200)
            window.location.href = "employees.html";
        else
            alert(result.Error);

    }
    async function GetEmployee() {
        var result = await HomeGetEmployee(employeeID);
        empInfoBlock = new Vue({
            el: '#empInfo',
            data: result
        });
    }


    function getUrlVars() {
        var vars = [], hash;
        var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
        for (var i = 0; i < hashes.length; i++) {
            hash = hashes[i].split('=');
            vars.push(hash[0]);
            vars[hash[0]] = hash[1];
        }
        return vars;
    }

</script>
</html>